home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Type casting
- Date: 1 Mar 1996 13:02:21 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4h7oktINN433@anvil.ugrad.cs.ubc.ca>
- References: <4gfnmi$gsc@calvin.risq.qc.ca> <4h5amm$dpv@umbc9.umbc.edu>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <4h5amm$dpv@umbc9.umbc.edu>,
- Jonas J. Schlein <schlein@umbc.edu> wrote:
- >Pierre Coulombe <pcoulomb@criq.qc.ca> wrote:
- >|> I have a problem with type casting in Visual C 1.5.
- >|> I expected the following program to print the value 254 for valI.
- >|> Instead it gives the output shown below.
- >|> Can someone tell me where is my mistake ?
- >|>
- >|>
- >|> ******** Program *********
- >|>
- >|> #include <stdio.h>
- >|> #include <string.h>
- >|> #include <stdlib.h>
- >|>
- >|> typedef unsigned int UINT;
- >|>
- >|> #define MM_TO_UNITS 10.0F
- >|>
- >|> void main(void)
- >
- >That's a no-no on c.l.c...Please read the FAQ and then you will fully
- >understand why for your program a correct definition is 'int main (void)'.
-
- The reason is a few sentences early in the ISO standard which say that main()
- shall be declared such and such, as I was surprised to find!
-
- Any further justifications may be informative, but are actually superfluous. If
- the assertion were removed from the standard, it would be legal to declare
- main() any way you like, and the conforming environment would have to make sure
- to call it with a compatible sequence no matter how you define this. This _can_
- be done---for instance, the compiler, upon seeing a definition of main(), could
- insert a hidden function which can be called by the environment in a consistent
- manner, and which calls main() using a compatible calling sequence tailored to
- the definition of main(). Thus arguments about things like calling conventions
- are irrelevant. The standard only requires that function calls _within_ the
- program are compatible with the matching function definitions. However, main()
- is not called from an expression within the C program, so this rule doesn't
- apply to it.
-
- You are required to write main() a certain way if you expect to write standard
- C, and that is all there is to it. There is no necessary reason why it _has_ to
- be that way.
-
- Incidentally, the only specific reference to undefined behavior in the context
- of main() that I have been able to dig up in the Standard says that the exit
- status of a program which doesn't provide a return value on exit from main() is
- undefined. There is no discussion over T main() where T is not int, versus int
- main().
- --
-
-